#这是一个运行在远端服务器上部署的脚本，用于拉取最新代码并构建admin页面，然后发布到服务器上
#注意：该脚本需要在服务器上运行，且需要安装git、npm、node等环境
#!/bin/bash

set -e 
declare current_dir=$(pwd)
echo "当前目录$current_dir"
echo "Step 1: 拉取最新wuhan_local代码"
cd ./wuhan_local && git pull ||  { echo "cd wuhan_local && git pull failed"; exit 1; }
cd "$current_dir"
echo "代码更新成功"
echo "Step 2:构建admin页面"
echo "Step 2-1:删除旧构建"
rm -rf wuhan_local/admin/dist/  || { echo "rm -rf wuhan_local/admin/dist/ failed"; exit 1; }
echo "删除旧构建成功,开始新构建"
cd ./wuhan_local/admin/ && npm run build:prod || { echo "cd wuhan_local/admin/ && npm run build:prod failed"; exit 1; }
cd "$current_dir"
echo "构建admin页面成功"
echo "Step 3:发布admin页面"
echo "Step 3-1:删除旧admin页面，注意删除后会导致访问出错"
rm -rf /home/magbbs/admin/ || { echo "rm -rf /home/magbbs/admin/  failed"; exit 1; }
echo "删除旧admin页面完成，开始发布新admin页面"
cp -r wuhan_local/admin/dist/ /home/magbbs/admin/ || { echo "cp -r wuhan_local/admin/dist/ /home/magbbs/admin/  failed"; exit 1; }
echo "发布admin页面完成"

